package cn.fl.warrant.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.comm.facade.upload.condition.SysUlFilesRecQueryCondition;
import cmm.mid.core.framework.dto.BaseParamDTO;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.user.facade.system.api.ISysOrgApiService;
import cmm.user.facade.system.api.ISysUsrApiService;
import cmm.user.facade.system.condition.SysUsrQueryCondition;
import cmm.user.facade.system.dto.SysOrgDTO;
import cmm.user.facade.system.dto.SysUsrDTO;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.framework.base.constant.WebBaseConstant;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.project.api.IProjectSpecialApiService;
import cn.fl.project.condition.PrjBscInfoQueryCondition;
import cn.fl.project.condition.PrjPrdDtlQueryCondition;
import cn.fl.project.dto.PrjPrdDtlDTO;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.project.service.IPrjPrdDtlService;
import cn.fl.project.vo.PrjBscInfoVO;
import cn.fl.project.vo.PrjPrdDtlVO;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysUlFilesRecService;
import cn.fl.system.vo.SysUlFilesRecVO;
import cn.fl.warrant.service.IArcBorrowDetailService;
import cn.fl.warrant.service.IArcBorrowMainService;
import cn.fl.warrant.service.IArcBscInfoService;
import cn.fl.warrant.service.IArcLocalContractUserService;
import cn.fl.warrant.service.IArcMgrDetailService;
import cn.fl.warrant.service.IArcMgrMainService;
import cn.fl.warrant.service.IArcPostInfoService;
import cn.fl.warrant.utils.JsonUtil;
import cn.fl.warrant.vo.ArcBorrowDetailVO;
import cn.fl.warrant.vo.ArcBorrowMainVO;
import cn.fl.warrant.vo.ArcLocalContractUserVO;
import cn.fl.warrant.vo.ArcMgrDetailVO;
import cn.fl.warrant.vo.ArcMgrMainVO;
import cn.fl.warrant.vo.ArcPostInfoVO;
import cn.fl.warrant.vo.ArcReceiptDetailVO;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.flow.facade.flow.dto.FlowStartedDTO;
import fl.warrant.facade.archive.api.IArcSwitchDetailApiService;
import fl.warrant.facade.archive.condition.ArcBorrowDetailQueryCondition;
import fl.warrant.facade.archive.condition.ArcBorrowMainQueryCondition;
import fl.warrant.facade.archive.condition.ArcLocalContractUserQC;
import fl.warrant.facade.archive.condition.ArcMgrDetailQC;
import fl.warrant.facade.archive.condition.ArcMgrMainQC;
import fl.warrant.facade.archive.condition.ArcPostInfoQC;
import fl.warrant.facade.archive.condition.ArcSwitchDetailQC;
import fl.warrant.facade.archive.constant.ArchiveConstants;
import fl.warrant.facade.archive.dto.ArcSwitchDetailDTO;

/**
 * @Description: 借阅业务 控制层
 */
@Controller
@RequestMapping("/archive/arcBorrowMain")
public class ArcBorrowMainController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(ArcBorrowMainController.class);
	
	@Autowired
	private IArcBscInfoService arcBscInfoService;
	@Autowired
	private IArcBorrowMainService arcBorrowMainService;//借阅主表
	@Autowired
	private IArcBorrowDetailService arcBorrowDetailService;//借阅明细
	@Autowired
	private IArcMgrMainService arcMgrMainService;//档案主表
	@Autowired
	private IArcMgrDetailService arcMgrDetailService;//档案明细
	@Autowired
	private IArcPostInfoService arcPostInfoService;//邮寄
	@Autowired
	private ICstBscInfoService cstBscInfoService;//客户
	@Autowired
	private ISysUsrApiService sysUsrApiService;
	@Autowired
	private ISysUlFilesRecService sysUlFilesRecService;//附件
	@Autowired
    private ISysOrgApiService sysOrgApiService;// 组织机构
	@Autowired
	private IPrjBscInfoService prjBscInfoService;//项目
	@Autowired
	private IProjectSpecialApiService projectSpecialApiService;
	@Autowired
	private IPrjPrdDtlService prjPrdDtlService;
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;
	@Autowired
	private IArcLocalContractUserService arcLocalContractUserService;//属地合同管理员配置
	@Autowired
	private IArcSwitchDetailApiService arcSwitchDetailApiService;
	/**
	 * 跳转到列表页面
	 */
	@RequestMapping("/toListPage.do")
	public String toListPage(HttpServletRequest request) {

		// 业务类型
		// List<KeyValueVO> bizTypeList = prjBscInfoService.getBizTypeList();
		// request.setAttribute("bizTypeList", bizTypeList);

		// 支付表状态
		// request.setAttribute("prdStsCdList",
		// this.prjBscInfoService.getPrdStsCdList());
		// 放款状态
		// request.setAttribute("payStsCdList",
		// this.sysDictionaryApiService.getKvList(CapPayInfoConstant.CODE_PAY_STS_CD,
		// sysCd,orgCd));

		// 客户类型
		request.setAttribute("cstTypCdList",
				this.cstBscInfoService.searchCstTypCdList());
		// 获取归档状态
		request.setAttribute("archiveStateList",
				arcMgrMainService.getStorageStatusList());
		// 事业部
		List<KeyValueVO> orgList = this.cstBscInfoService
				.searchBusinessOrgList();
		request.setAttribute("buOrgCdList", orgList);
		// 省公司
		request.setAttribute("prList", arcMgrMainService.getPrList());
		return "archive/arcBorrowMain/arcBorrowMainList";
	}

	/**
	 * 列表页面查询
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/initList.do")
	@ResponseBody
	public Object initList(ArcMgrMainQC qc,HttpServletRequest request) {
	
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		if(StringUtils.isBlank(qc.getStorageStatus())) {
			qc.setStorageStatusForBorrow("3;4");
		}else {
			qc.setStorageStatusForBorrow(qc.getStorageStatus());
		}
		//权限添加
		qc.setUsrId(CurrentThreadContext.getCurrentUserId());
		page.setCondition(qc);
	
		Pager pager = this.arcMgrMainService.selectListForListPage(page);
		ListPageVO<ArcMgrMainVO> listPage = new ListPageVO<ArcMgrMainVO>((List<ArcMgrMainVO>) pager.getResultList(), pager.getTotalCount());
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}

	
	/**
	 * 跳转到保存页面(新增和修改)
	 */
	@RequestMapping(value = "/borrowApply.do")
	public Object borrowApply(ArcBorrowMainVO arcBorrowMainVO,HttpServletRequest request) {

		//1、查询档案管理主表，获取 合同号、交接单名称、档案袋号
		ArcMgrMainQC qc = new ArcMgrMainQC();
		qc.setContractNo(arcBorrowMainVO.getContractNo());
		List<ArcMgrMainVO> arcMgrMainVOList = arcMgrMainService.selectList(qc);
		if(arcMgrMainVOList != null && arcMgrMainVOList.size() >0) {
			request.setAttribute("arcMgrMainVO", arcMgrMainVOList.get(0));
		}
		
		//2、保存前台勾选的多个支付表号
		if(StringUtils.isNotBlank(arcBorrowMainVO.getPaySchNoList())) {
			request.setAttribute("paySchNoArray",arcBorrowMainVO.getPaySchNoList().split(";"));
		}
		
		//3、设置下拉select
		this.setDic(request);
		
		return "archive/arcBorrowMain/arcBorrowMainSave";
	}

	private void setDic(HttpServletRequest request) {
		String sysCd = CurrentThreadContext.getCurrentSysCd(); 
		String orgCd = CurrentThreadContext.getCurrentOrgCd();
		
		request.setAttribute("sendTypeList", arcBscInfoService.getKvList(sysCd, orgCd, ArchiveConstants.ARC010));//接收方式
		request.setAttribute("borrowTypeList", arcBscInfoService.getKvList(sysCd, orgCd, ArchiveConstants.DIC_BORROW_TYPE));//借阅类型
		request.setAttribute("sendCompanyList", arcBscInfoService.getKvList(sysCd, orgCd, ArchiveConstants.ARC012));//邮寄公司
	}
	
	/**
	 * 发起借阅申请(数据保存和流程发起)
	 */
	@RequestMapping(value = "/borrowApplyStart.do")
	@ResponseBody
	public Object borrowApplyStart(ArcBorrowMainVO entity,HttpServletRequest request){
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		try {
			
//				/**
//				 * 验证：如果当前角色为客户经理、分公司经理、城市经理（数据字典配置 ARC023）,则需要判断客户是否逾期
//				 * ，如果逾期不允许发起借阅流程
//				 */
//			
//				Long currentRoleId = CurrentThreadContext.getCurrentRoleId();//当前角色ID
//				List<KeyValueVO> keyValueVOList = arcBscInfoService.getKvList(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd()
//						, ArchiveConstants.DIC_BORROW_ROLE);//配置的角色列表
//				BaseLogUtils.info(logger, null, "是否需要判断客户是否逾期开始 currentRoleId:"+currentRoleId +" keyValueVOList:"+ JSONObject.toJSONString(keyValueVOList), CurrentThreadContext.getCurrentUserName());
//				if(currentRoleId != null && CollectionUtils.isNotEmpty(keyValueVOList)) {
//					for (KeyValueVO keyValueVO : keyValueVOList) {
//						if(currentRoleId.toString().equals(keyValueVO.getKey())) {
//							//需要验证当前角色，查询客户是否有逾期，如果有逾期，则不能发起借阅
//							if(StringUtils.isNotBlank(entity.getContractNo())) {
//								
//								PrjBscInfoQueryCondition qc = new PrjBscInfoQueryCondition();
//								qc.setLsCntNo(entity.getContractNo());
//								BaseLogUtils.info(logger, null, "根据合同号查询客户id开始,qc:"+ JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
//								List<PrjBscInfoVO> prjBscInfoVOList = prjBscInfoService.searchPrjBscInfoList(qc);
//								BaseLogUtils.info(logger, null, "根据合同号查询客户id结束,prjBscInfoVOList:"+ JSONObject.toJSONString(prjBscInfoVOList), CurrentThreadContext.getCurrentUserName());
//								
//								if(CollectionUtils.isNotEmpty(prjBscInfoVOList)){
//									
//									Long cstId = prjBscInfoVOList.get(0).getCstId();
//									BaseLogUtils.info(logger, null, "根据客户id查询是否逾期开始,cstId:"+ cstId, CurrentThreadContext.getCurrentUserName());
//									Long relCstId = this.arcBorrowMainService.selectCstIsOvd(cstId);
//									BaseLogUtils.info(logger, null, "根据客户id查询是否逾期结束,relCstId:"+ relCstId, CurrentThreadContext.getCurrentUserName());
//									
//									if(relCstId != null) {
//										result.setSuccess(BaseConstant.IS_YESNO_NO);
//										result.setInfo("该客户存在逾期，不可发起借阅");
//										return result;
//									}
//								}
//							}
//							
//							break;
//						}
//					}
//				}
			
				//1、数据保存
				String _arcBorrowDetailList = request.getParameter("_arcBorrowDetailList");
//				entity.setArcBorrowDetailList(JSONArray.parseArray(_arcBorrowDetailList, ArcBorrowDetailVO.class));
				entity.setArcBorrowDetailList((List<ArcBorrowDetailVO>) JsonUtil.toList(_arcBorrowDetailList, new ArcBorrowDetailVO()));//合同和支付表明细
				
				entity.setIsValid(ArchiveConstants.IS_VALID);
				entity.setIsDel(ArchiveConstants.IS_DEL);
				entity.setCrtTm(new Date());
				entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
				entity.setCrtUsrNa(CurrentThreadContext.getCurrentUserName());
				entity.setCstMgrId(CurrentThreadContext.getCurrentUserId());
				entity.setCstMgrNm(CurrentThreadContext.getCurrentUserName());
				entity.setCstMgrOrgCd(CurrentThreadContext.getCurrentOrgCd());
				
				Long id = this.arcBorrowMainService.borrowApplyStart(entity);
				result.setData(id);
			
				BaseLogUtils.info(logger, "borrowApplyStart", "操作数据. DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
				
				//2、流程发起
				result = borrowApplyStartFlow(id,entity);
				
				
		}catch (Exception ex) {
			ex.printStackTrace();
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "borrowApplyStart", "操作数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	
	/**
	 * 流程发起
	 */
	private DataResultVO borrowApplyStartFlow(Long id,ArcBorrowMainVO entity) {
		
//		String procDefKey="FLOW_0000_ARC02_001";
//		String procDefId="FLOW_0000_ARC02_001:1:7603537b-21a5-11e8-a7e1-005056b1519e";
//		String procNo="权证借阅申请流程";
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "borrowApplyStartFlow", SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY, CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
		try {
			//流程定义Key和流程定义ID 如果是前端选择的则直接指定,如果不是则系统自动按照配置选择唯一一条记录,如果找不到会提示
			flowStartParamsDTO.setBusinessKey(String.valueOf(id));
			flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
			flowStartParamsDTO.setWordsInTheTable(ArchiveConstants.ARC_FLOW_S_H_ARC);
			flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			flowStartParamsDTO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
			flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
			flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
			flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);//优先级,可以在界面定义
			//代表任务中承租人信息
//			flowStartParamsDTO.setCstId();
			flowStartParamsDTO.setCstNm(arcBorrowMainService.getCstNm(entity.getContractNo()));
			flowStartParamsDTO.setModelTyp(ArchiveConstants.FLOW_MODEL_TYP_ARC_BORROW);//需要和流程配置中的模块类型匹配

			
			//设置关键字 开始
			StringBuffer keyWords = new StringBuffer();
			
			/**
			 *        重卡:集团0000-重卡事业部0001-京津冀大区0002-石家庄区域0002
			 * 二手车：集团0000-重卡事业部0001-二手车0024-湖北省分公司0001
		           汽车金融：集团0000-汽车金融事业部0005-华东区0001-安徽省公司0001
			 * 新能源：集团0000-新能源汽车事业部0013-四川省0001
			 */
			String cstMgrOrgCd = arcBorrowMainService.getCstMgrOrgCd(entity.getContractNo());//根据合同号获取客户经理组织架构
			if(StringUtils.isNotBlank(cstMgrOrgCd)) {
//				List<SysOrgDTO> sysOrgDTOList = this.sysOrgApiService.searchSysOrgListBy(CurrentThreadContext.getCurrentSysCd()); //查询所有组织架构列表
				if(cstMgrOrgCd.length() > 4*4) {//统一截取到第四级
					cstMgrOrgCd = cstMgrOrgCd.substring(0,4*4);
				}
				SysOrgDTO sysOrgDTO = this.sysOrgApiService.selectSysOrgByOrgCd(cstMgrOrgCd, CurrentThreadContext.getCurrentSysCd());
				if(sysOrgDTO != null) {
					keyWords.append(sysOrgDTO.getOrgDispNm()).append(FlowConstant.FLOW_TASK_BACK_USR_DISPLAY_SEPERATOR);//组织架构（架构显示名称,例如:重卡-江苏-南京分公司）
				}
			}
			keyWords.append(entity.getContractNo()).append(FlowConstant.FLOW_TASK_BACK_USR_DISPLAY_SEPERATOR);//合同号
			
			//关键字增加车架号
			List<ArcBorrowDetailVO> arcBorrowDetailList = entity.getArcBorrowDetailList();
			if(arcBorrowDetailList != null && arcBorrowDetailList.size() >0) {
				for (ArcBorrowDetailVO arcBorrowDetailVO : arcBorrowDetailList) {
					if(StringUtils.isNotBlank(arcBorrowDetailVO.getPaylistCode())) {
						PrjPrdDtlQueryCondition dtlQc = new PrjPrdDtlQueryCondition();
						dtlQc.setPaySchNo(arcBorrowDetailVO.getPaylistCode());
						
						BaseParamDTO baseParamDTO = new BaseParamDTO();
						baseParamDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
						baseParamDTO.setChannelCd(WebBaseConstant.CHANNEL_CD);
			            baseParamDTO.setFrontCd(PropertiesCacheUtils.getProperty(WebBaseConstant.FL_SERVICE_SYS_CD));
			            baseParamDTO.setServiceCd(PropertiesCacheUtils.getProperty(WebBaseConstant.FL_SERVICE_SYS_CD));
			            
						List<PrjPrdDtlDTO> prjPrdDtlDTOList = this.projectSpecialApiService.searchPrjPrdDtlDTOList(dtlQc, baseParamDTO);
						if(prjPrdDtlDTOList != null && prjPrdDtlDTOList.size() > 0) {
							for (PrjPrdDtlDTO prjPrdDtlDTO : prjPrdDtlDTOList) {
								if(StringUtils.isNotBlank(prjPrdDtlDTO.getVin())) {
									keyWords.append(prjPrdDtlDTO.getVin()).append(FlowConstant.FLOW_TASK_BACK_USR_DISPLAY_SEPERATOR);
								}
								
							}
						}
					}
				}
			}
			
				
			
			
			flowStartParamsDTO.setSearchDesc(keyWords.toString()); 
			BaseLogUtils.info(logger, "borrowApplyStartFlow", "keyWords：" +keyWords.toString(), CurrentThreadContext.getCurrentUserName());
			//设置关键字 结束
			
			/**
			 * 1、发起人为客户经理(manager),流程：业务发起人（客户经理）-合同管理员-省总-事业部风控（重卡沈旭东）-权证寄出
			 * 2、发起人为非客户经理(noManager),流程：后台发起人（事业部成员）-直属领导-权证寄出
			 */
			Map<String, Object> startParams = new HashMap<String, Object>();
			startParams.put("originator", "noManager");//默认非客户经理(noManager)
			
			if(entity != null && StringUtils.isNotBlank(entity.getContractNo())) {
				PrjBscInfoQueryCondition qc = new PrjBscInfoQueryCondition();
				qc.setCntNo(entity.getContractNo());
				List<PrjBscInfoVO> prjBscInfoVOList = prjBscInfoService.searchPrjBscInfoList(qc);
				if(prjBscInfoVOList != null && prjBscInfoVOList.size() >0) {
					for (PrjBscInfoVO prjBscInfoVO : prjBscInfoVOList) {
						if(prjBscInfoVO.getCstMgrId() != null && prjBscInfoVO.getCstMgrId().equals(CurrentThreadContext.getCurrentUserId())) {
							startParams.put("originator", "manager");
							break;
						}
					}
				}
			}
			
			/**
			 * 3、发起人为合同管理员(contract),流程：发起后-信审中心权证负责人审批
			 */
			Long currentRoleId = CurrentThreadContext.getCurrentRoleId();//当前角色ID
			List<KeyValueVO> keyValueVOList = arcBscInfoService.getKvList(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd()
					, "ARC024");//配置的角色列表
			BaseLogUtils.info(logger, null, "借阅申请判断发起人角色开始 currentRoleId:"+currentRoleId +" keyValueVOList:"+ JSONObject.toJSONString(keyValueVOList), CurrentThreadContext.getCurrentUserName());
			if(currentRoleId != null && CollectionUtils.isNotEmpty(keyValueVOList)) {
				for (KeyValueVO keyValueVO : keyValueVOList) {
					if(currentRoleId.toString().equals(keyValueVO.getKey())) {
						startParams.put("originator", "contract");
						break;
					}
				}
			}
			
			
			//设置属地管理员
			ArcLocalContractUserQC qc = new ArcLocalContractUserQC();
			qc.setOrgCode(entity.getCstMgrOrgCd());
			BaseLogUtils.info(logger, "", "设置属地管理员 ArcLocalContractUserQC："+JSONObject.toJSONString(qc));
			List<ArcLocalContractUserVO>  arcLocalContractUserVOList = arcLocalContractUserService.searchList(qc);
			BaseLogUtils.info(logger, "", "设置属地管理员 arcLocalContractUserVOList："+JSONObject.toJSONString(arcLocalContractUserVOList));
			if(CollectionUtils.isNotEmpty(arcLocalContractUserVOList)
					&& arcLocalContractUserVOList.size() > 0) {
				ArcLocalContractUserVO arcLocalContractUser = arcLocalContractUserVOList.get(0);
				String userIds = arcLocalContractUser.getUserIds();
				if(StringUtils.isNotEmpty(userIds)){
					BaseLogUtils.info(logger, "", "设置属地管理员 userIds："+userIds);
					startParams.put("prAssignee",userIds.split(";"));
				}
			}
			
			flowStartParamsDTO.setStartParams(startParams);
			
			DataResultDTO dataResultDTO = this.arcBorrowMainService.addFlowStart(flowStartParamsDTO);
			if(!dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
			}
			if(null!=dataResultDTO && null!=dataResultDTO.getData()){
				FlowStartedDTO flowStartedDTO = (FlowStartedDTO) dataResultDTO.getData();
				if(StringUtils.isNotBlank(flowStartedDTO.getNextOperUsrNames())){
	                result.setInfo("下一个节点操作人:"+flowStartedDTO.getNextOperUsrNames());
	            }else{
	                result.setInfo("流程发起成功");
	            }
			}
			
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "borrowApplyStartFlow", "错误[BaseException],请求参数：" + JSONObject.toJSONString(flowStartParamsDTO) + " -ERROR:" +e.getMessage(), CurrentThreadContext.getCurrentUserName());
			e.getStackTrace();
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "borrowApplyStartFlow", "错误[Exception],请求参数：" + JSONObject.toJSONString(flowStartParamsDTO) + " -ERROR:" +e.getMessage(), CurrentThreadContext.getCurrentUserName());
			e.getStackTrace();
		}
		return result;
	}
	
	
	/**
	 * 发起借阅申请修改
	 */
	@RequestMapping(value = "/borrowApplyUpdate.do")
	@ResponseBody
	public Object borrowApplyUpdate(ArcBorrowMainVO entity,HttpServletRequest request){
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
		try {
				//1、数据保存
				String _arcBorrowDetailList = request.getParameter("_arcBorrowDetailList");
				entity.setArcBorrowDetailList((List<ArcBorrowDetailVO>) JsonUtil.toList(_arcBorrowDetailList, new ArcBorrowDetailVO()));//合同和支付表明细
				
				entity.setIsValid(ArchiveConstants.IS_VALID);
				entity.setIsDel(ArchiveConstants.IS_DEL);
				entity.setCrtTm(new Date());
				entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
				entity.setCrtUsrNa(CurrentThreadContext.getCurrentUserName());
				entity.setCstMgrId(CurrentThreadContext.getCurrentUserId());
				entity.setCstMgrNm(CurrentThreadContext.getCurrentUserName());
				entity.setCstMgrOrgCd(CurrentThreadContext.getCurrentOrgCd());
				
				 this.arcBorrowMainService.borrowApplyUpdate(entity);
			
				BaseLogUtils.info(logger, "borrowApplyUpdate", "操作数据. DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
				
				
		}catch (Exception ex) {
			ex.printStackTrace();
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "borrowApplyUpdate", "操作数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 查询档案管理明细表，根据合同或支付表
	 * @throws ParseException 
	 */
	@RequestMapping("/arcMgrDetailList.do")
	@ResponseBody
	public Object arcMgrDetailList(ArcMgrDetailQC qc) throws ParseException {

		if(StringUtils.isBlank(qc.getContractNo()) && StringUtils.isBlank(qc.getPaylistCode())) {
			BaseLogUtils.info(logger, "arcMgrDetailList", "ContractNo和PaylistCode不能同时为空", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		
		qc.setDossierTemp(ArchiveConstants.ARC_TYPE_ORIGINAL);//只查询归档原件
		qc.setIsDel(BaseConstant.IS_YESNO_NO);
		
		List<ArcMgrDetailVO> arcMgrDetailVOList = arcMgrDetailService.searchList(qc);
		if(arcMgrDetailVOList != null && arcMgrDetailVOList.size() >0) {
			
			List<ArcMgrDetailVO> newArcMgrDetailVOList = new ArrayList<ArcMgrDetailVO>();
			
			String theDate = getTheDate();
			if(StringUtils.isNotBlank(theDate)) {
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				Date thisDate =  sdf.parse(theDate);
				
				for (ArcMgrDetailVO arcMgrDetailVO : arcMgrDetailVOList) {
					//2020-10-13以后新归档申请流程改版，借阅状态根据归档分数+归档状态
					//状态为已归档的资料，判断在特定日期之后，加上已归档数量>0才是真正已归档
					if("0".equals(arcMgrDetailVO.getBorrowStatus())) {//已归档,需判断是否真正已归档
						if(arcMgrDetailVO.getCrtTm() != null && arcMgrDetailVO.getCrtTm().after(thisDate)) {
							if(arcMgrDetailVO.getDossierCountT() != null &&
									arcMgrDetailVO.getDossierCountT().longValue() <= 0) {
								continue;
							}
						}
					}
					newArcMgrDetailVOList.add(arcMgrDetailVO);
				}
			}else {
				newArcMgrDetailVOList = arcMgrDetailVOList;
			}
			
			//归档地点修改:如果有转仓流程,则取终点,否则保持原来逻辑
			if(CollectionUtils.isNotEmpty(newArcMgrDetailVOList)) {
				ArcSwitchDetailQC arcSwitchDetailQC = new ArcSwitchDetailQC();
				arcSwitchDetailQC.setContractNo(qc.getContractNo());
				arcSwitchDetailQC.setPaylistCode(qc.getPaylistCode());
				arcSwitchDetailQC.setDossierTemp("1");//原件
				arcSwitchDetailQC.setIsValid(1);
				arcSwitchDetailQC.setIsDel(0);
				
				BaseLogUtils.info(logger, "", "如果有转仓流程,则取终点ArcSwitchDetailQC："+JSONObject.toJSONString(arcSwitchDetailQC));
				List<ArcSwitchDetailDTO> arcSwitchDetailDTOList = this.arcSwitchDetailApiService.searchList(arcSwitchDetailQC);
				BaseLogUtils.info(logger, "", "如果有转仓流程,则取终点arcSwitchDetailDTOList："+JSONObject.toJSONString(arcSwitchDetailDTOList));
				
				if (CollectionUtils.isNotEmpty(arcSwitchDetailDTOList)) {
					for (ArcMgrDetailVO arcMgrDetailVO : newArcMgrDetailVOList) {
						for (ArcSwitchDetailDTO arcSwitchDetailDTO : arcSwitchDetailDTOList) {
							// 设置归档终点
							ArcReceiptDetailVO arcReceiptDetailVO = arcMgrDetailVO.getArcReceiptDetailVO();
							if (StringUtils.isNotBlank(arcMgrDetailVO.getFileName())
									&& arcMgrDetailVO.getFileName().equals(arcSwitchDetailDTO.getFileName())) {
								if (arcReceiptDetailVO != null
										&& StringUtils.isNotBlank(arcSwitchDetailDTO.getPlaceEndNm())) {
									arcReceiptDetailVO.setArcPlaceNm(arcSwitchDetailDTO.getPlaceEndNm());
									break;
								}
							}
						}
					}
				}
			}
			
			//设置扫描件
			for (ArcMgrDetailVO arcMgrDetailVO : newArcMgrDetailVOList) {
				this.setArcMgrDetailVOScanAttche(arcMgrDetailVO);
			}
			return new ListPageVO<ArcMgrDetailVO>(newArcMgrDetailVOList, newArcMgrDetailVOList.size());
		}
		return null;
	}

	
	//获取数据字典特定日期，用于新归档申请流程改版，借阅状态根据归档分数+归档状态
	private String getTheDate() {
		String theDate = "";
		List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService
				.searchGroup(CurrentThreadContext.getCurrentSysCd()
						, CurrentThreadContext.getCurrentOrgCd(), "REF0054");
		if (sysDictionaryDTOList != null && sysDictionaryDTOList.size() > 0) {
			for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
					theDate = sysDictionaryDTO.getCode();
					break;
			}
		}
		return theDate;
	}
	
		//设置扫描件
		private void setArcMgrDetailVOScanAttche(ArcMgrDetailVO arcMgrDetailVO) {

			SysUlFilesRecQueryCondition qc = new SysUlFilesRecQueryCondition();
			if(arcMgrDetailVO != null && arcMgrDetailVO.getId() != null) {
				qc.setPkId(String.valueOf(arcMgrDetailVO.getId()));
//				qc.setCfgCd(FncPrjContMainConstant.FNC_PRJ_CONT_CFGCD);
//				qc.setCfgDtlCd(FncPrjContMainConstant.FNC_PRJ_CONT_CFGDTLCD_20);
//				qc.setTabNm(FncPrjContMainConstant.FNC_PRJ_CONT_DETAIL_TABNM);
				qc.setSysCd(CurrentThreadContext.getCurrentSysCd());
				List<SysUlFilesRecVO> contDetailAttachList = this.sysUlFilesRecService.searchList(qc);
				arcMgrDetailVO.setScanAttcheList(contDetailAttachList);
			}
			
		}
	/**
	 * 获取借阅用途
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getBorrowUse.do")
	@ResponseBody
	public Object getBorrowUse(HttpServletRequest request) throws BaseException {
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_NO, SysLogConstant.LOG_CMM_OPERATE_FAIL);
		try {
			String code = request.getParameter("code");
			if(StringUtils.isNotBlank(code)){
				List<KeyValueVO> keyValueVOList = this.arcBscInfoService.getKvList(ArchiveConstants.DIC_BORROW_USE, code,
						CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
				if(CollectionUtils.isNotEmpty(keyValueVOList)){
					result.setData(JSONArray.toJSON(keyValueVOList));
				}
				result.setSuccess(BaseConstant.IS_YESNO_YES);
				BaseLogUtils.info(logger, "getBorrowUse", "获取数据成功."+keyValueVOList, CurrentThreadContext.getCurrentUserName());
			}
			
		}catch(BaseException ex) {
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "getBorrowUse", "获取-失败."+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch(Exception ex) {
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "getBorrowUse", "获取失败."+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 获取系统用户(工号、姓名)
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/getSysUsr.do")
	@ResponseBody
	public Object getSysUsr(HttpServletRequest request) throws BaseException {
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_NO, SysLogConstant.LOG_CMM_OPERATE_FAIL);
		try {
			String jobNum = request.getParameter("jobNum");//工号
			if(StringUtils.isNotBlank(jobNum)){
				SysUsrDTO sysUsrDTO = this.sysUsrApiService.selectSysUsrWithAuthBy(CurrentThreadContext.getCurrentSysCd(), jobNum);
				if(sysUsrDTO==null){
					//判断是否根据工号查询出人员了，如果是，则不继续，否则继续根据姓名查一下
					SysUsrQueryCondition ssyqc=new SysUsrQueryCondition();
					ssyqc.setRlNm(jobNum);
					ssyqc.setSysCd(CurrentThreadContext.getCurrentSysCd()); 
					List<SysUsrDTO> userList=sysUsrApiService.searchSysUsrList(ssyqc);
					if(userList!=null && userList.size()>0){
						sysUsrDTO=userList.get(0);
					}
				}
				result.setData(sysUsrDTO);
				
				result.setSuccess(BaseConstant.IS_YESNO_YES);
				result.setInfo("");
				BaseLogUtils.info(logger, "getSysUsr", "获取数据成功."+sysUsrDTO, CurrentThreadContext.getCurrentUserName());
			}
			
		}catch(Exception ex) {
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "getSysUsr", "获取-失败."+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	
	/**
	 * 流程附件页面
	 */
	@RequestMapping(value = "/view.do")
	public Object view(Long id,HttpServletRequest request) {

		request.setAttribute("id", id);
		//1、查询借阅主表，获取 合同号、交接单名称、档案袋号
		if(id != null) {
			ArcBorrowMainVO arcBorrowMainVO = this.arcBorrowMainService.selectById(id);
			if(arcBorrowMainVO != null) {
				//2、查询当前借阅下对应的支付表号
				List<String> paySchNoList = new ArrayList<String>();
				ArcBorrowDetailQueryCondition qc = new ArcBorrowDetailQueryCondition();
				qc.setArcBorrowMainId(arcBorrowMainVO.getId());
				qc.setArcLevel(ArchiveConstants.ARCLEVEL_2);
				List<ArcBorrowDetailVO> arcBorrowDetailVOList = this.arcBorrowDetailService.searchList(qc);
				if(arcBorrowDetailVOList != null && arcBorrowDetailVOList.size() >0) {
					for (ArcBorrowDetailVO arcBorrowDetailVO : arcBorrowDetailVOList) {
						if(StringUtils.isNotBlank(arcBorrowDetailVO.getPaylistCode()) && !paySchNoList.contains(arcBorrowDetailVO.getPaylistCode())) {
							
							//查询车架号：先根据支付表号获取支付表id，根据支付表id获取车架号
							ArcMgrMainQC arcMgrMainQC = new ArcMgrMainQC();
							arcMgrMainQC.setPaySchNo(arcBorrowDetailVO.getPaylistCode());
							List<ArcMgrMainVO> arcMgrMainVOList = arcMgrMainService.selectList(arcMgrMainQC);
							if(CollectionUtils.isNotEmpty(arcMgrMainVOList)) {
								ArcMgrMainVO arcMgrMainVO = arcMgrMainVOList.get(0);
								if(arcMgrMainVO.getPaySchId() != null) {
									PrjPrdDtlQueryCondition prjPrdDtlQueryCondition = new PrjPrdDtlQueryCondition();
									prjPrdDtlQueryCondition.setPaySchId(arcMgrMainVO.getPaySchId());
				                    List<PrjPrdDtlVO> dtlList = this.prjPrdDtlService.selectList(prjPrdDtlQueryCondition);
				                    if (CollectionUtils.isNotEmpty(dtlList)) {
				                    	PrjPrdDtlVO dtl = dtlList.get(0);
				                    	arcBorrowDetailVO.setVin(dtl.getVin());//设置车架号
				                    }
								}
							}
							
							paySchNoList.add(arcBorrowDetailVO.getPaylistCode());
						}
					}
				}
				
				//查询承租人
				if(StringUtils.isNotBlank(arcBorrowMainVO.getContractNo())) {
					arcBorrowMainVO.setCstNm(arcBorrowMainService.getCstNm(arcBorrowMainVO.getContractNo()));
				}
				
				request.setAttribute("arcBorrowDetailVOList", arcBorrowDetailVOList);
				request.setAttribute("paySchNoList", paySchNoList);
				request.setAttribute("arcBorrowMainVO", arcBorrowMainVO);
			}
		}
		
		//2、设置下拉select
		this.setDic(request);
		
		//3、判断当前哪个节点
		String from = request.getParameter("from");
		request.setAttribute("from", from);
		
		if("postProvince".equals(from)) {//档案管理员邮寄资料（省公司）
			
			//查询要修改的邮寄信息
			request.setAttribute("arcPostInfoVO", this.setDefaultPostInfo(id,ArchiveConstants.ARC_POST_INFO_BUSS_BORROW_2));
			request.setAttribute("arcAppBussType", ArchiveConstants.ARC_POST_INFO_BUSS_BORROW_2);//设置申请业务类型
		}else if("postZong".equals(from)) {//档案管理员邮寄资料（总部）
			
			//查询要修改的邮寄信息
			request.setAttribute("arcPostInfoVO", this.setDefaultPostInfo(id,ArchiveConstants.ARC_POST_INFO_BUSS_BORROW_3));
			request.setAttribute("arcAppBussType", ArchiveConstants.ARC_POST_INFO_BUSS_BORROW_3);//设置申请业务类型
		}else if("borrowerReturn".equals(from)) {//借阅人归还
			//判断是否含省公司、总公司
			Map<String, Object> parms = judgeReturnConfirm(id);
			if("1".equals(parms.get("confirmProvince"))) {//经过省公司
				request.setAttribute("arcPostInfoVOProvince", getArcPostInfo(id,ArchiveConstants.ARC_POST_INFO_BUSS_BORROW_4));//查询要修改的邮寄信息
				request.setAttribute("arcAppBussTypeProvince", ArchiveConstants.ARC_POST_INFO_BUSS_BORROW_4);//设置申请业务类型
			}
			if("1".equals(parms.get("confirmZong"))) {//经过总公司
				request.setAttribute("arcPostInfoVOZong", getArcPostInfo(id,ArchiveConstants.ARC_POST_INFO_BUSS_BORROW_5));//查询要修改的邮寄信息
				request.setAttribute("arcAppBussTypeZong", ArchiveConstants.ARC_POST_INFO_BUSS_BORROW_5);//设置申请业务类型
			}
		}else if("creatorUpdate".equals(from)) {//发起人从新提交，跳转修改页面
			
			request.setAttribute("arcPostInfoVO", getArcPostInfo(id,ArchiveConstants.ARC_POST_INFO_BUSS_BORROW));//查询申请人邮寄信息
			return "archive/arcBorrowMain/arcBorrowMainUpdate";
		}
		
		
		return "archive/arcBorrowMain/arcBorrowMainView";
	}
	
	private ArcPostInfoVO setDefaultPostInfo(Long id,String arcAppBussTypes) {
		
		ArcPostInfoVO arcPostInfoVO = getArcPostInfo(id,arcAppBussTypes);
		if(arcPostInfoVO == null) {
			//默认查询申请人邮寄信息，作为默认邮寄信息
			arcPostInfoVO = getArcPostInfo(id,ArchiveConstants.ARC_POST_INFO_BUSS_BORROW);
			if(arcPostInfoVO !=null) {
				arcPostInfoVO.setId(null);
				if("0".equals(arcPostInfoVO.getSendType())) {
					//如果是邮寄，需要设置快递公司为顺丰；清空快递单号
					arcPostInfoVO.setSendCompany("SF");
					arcPostInfoVO.setSendNum(null);
				}
			}
		}
		return arcPostInfoVO;
	}
	
	//判断是归还确认，是否经过档案管理员确认(省公司)、档案管理员确认(总公司)
		private Map<String, Object>  judgeReturnConfirm(Long id) {
			Map<String, Object> parms = new HashMap<String, Object>();
			
			ArcBorrowDetailQueryCondition qc = new ArcBorrowDetailQueryCondition();
			qc.setArcBorrowMainId(id);
			qc.setIsDel(ArchiveConstants.IS_DEL);
			List<ArcBorrowDetailVO> arcBorrowDetailVOList=  arcBorrowDetailService.searchList(qc);
			if(arcBorrowDetailVOList != null && arcBorrowDetailVOList.size() >0) {
				for (ArcBorrowDetailVO arcBorrowDetailVO : arcBorrowDetailVOList) {
					//帅选需要归还的记录
					if(arcBorrowDetailVO != null && "1".equals(arcBorrowDetailVO.getOriginalReturn())) {
						ArcMgrDetailVO arcMgrDetailVO =this.arcMgrDetailService.selectById(arcBorrowDetailVO.getArcMgrDetailId());
						if(arcMgrDetailVO != null) {
							if("1".equals(arcMgrDetailVO.getArcReceiptDetailVO().getArcPlace())) {
								parms.put("confirmZong", "1");//需要经过档案管理员确认(总公司)
							}else if("2".equals(arcMgrDetailVO.getArcReceiptDetailVO().getArcPlace())) {
								parms.put("confirmProvince", "1");//需要经过档案管理员确认(省公司)
							}
						}
					}
				}
			}
			
			return parms;
		} 
		
	//查询要修改的邮寄信息
	private ArcPostInfoVO getArcPostInfo(Long id,String arcAppBussTypes) {
		if(id == null) return null;
		
		ArcPostInfoQC qc = new ArcPostInfoQC();
		qc.setArcAppType(ArchiveConstants.ARC_POST_INFO_BORROW);//借阅类型
		qc.setIsDel(ArchiveConstants.IS_DEL);
		qc.setArcAppId(id);//借阅申请主表id
		qc.setArcAppBussTypes(arcAppBussTypes);
		
		List<ArcPostInfoVO> arcPostInfoVOList = this.arcPostInfoService.searchList(qc);
		if(arcPostInfoVOList != null && arcPostInfoVOList.size() >0) {
			return arcPostInfoVOList.get(0);
		}
		return null;
	}
	
	/**
	 * 流程附件页面：根据流程业务id，查询借阅明细表
	 */
	@RequestMapping("/arcBorrowDetailList.do")
	@ResponseBody
	public Object arcBorrowDetailList(ArcBorrowDetailQueryCondition qc) {

		if(qc.getArcBorrowMainId() != null && StringUtils.isNotBlank(qc.getArcLevel())) {
			qc.setIsDel(ArchiveConstants.IS_DEL);
			
			List<ArcSwitchDetailDTO> arcSwitchDetailDTOList = null;
			ArcBorrowMainVO arcBorrowMainVO = this.arcBorrowMainService.selectById(qc.getArcBorrowMainId());
			if(arcBorrowMainVO != null) {
				//设置归档地点:如果有转仓流程,则取终点,否则保持原来逻辑
				ArcSwitchDetailQC arcSwitchDetailQC = new ArcSwitchDetailQC();
				arcSwitchDetailQC.setContractNo(arcBorrowMainVO.getContractNo());
				arcSwitchDetailQC.setDossierTemp("1");//原件
				arcSwitchDetailQC.setIsValid(1);
				arcSwitchDetailQC.setIsDel(0);
				
				BaseLogUtils.info(logger, "", "流程附件页面:如果有转仓流程,则取终点ArcSwitchDetailQC："+JSONObject.toJSONString(arcSwitchDetailQC));
				arcSwitchDetailDTOList = this.arcSwitchDetailApiService.searchList(arcSwitchDetailQC);
				BaseLogUtils.info(logger, "", "流程附件页面:如果有转仓流程,则取终点arcSwitchDetailDTOList："+JSONObject.toJSONString(arcSwitchDetailDTOList));
			}
			
			
			List<ArcBorrowDetailVO> arcBorrowDetailVOList = arcBorrowDetailService.searchList(qc);
			if(arcBorrowDetailVOList != null && arcBorrowDetailVOList.size() >0) {
				for (ArcBorrowDetailVO arcBorrowDetailVO : arcBorrowDetailVOList) {
					if(arcBorrowDetailVO.getArcMgrDetailId() != null) {
						ArcMgrDetailVO arcMgrDetailVO = this.arcMgrDetailService.selectById(arcBorrowDetailVO.getArcMgrDetailId());
						this.setArcMgrDetailVOScanAttche(arcMgrDetailVO);//设置扫描件
						arcBorrowDetailVO.setArcMgrDetailVO(arcMgrDetailVO);
						
						//设置归档地点:如果有转仓流程,则取终点,否则保持原来逻辑
						if (CollectionUtils.isNotEmpty(arcSwitchDetailDTOList)) {
							for (ArcSwitchDetailDTO arcSwitchDetailDTO : arcSwitchDetailDTOList) {
								// 设置归档终点
								ArcReceiptDetailVO arcReceiptDetailVO = arcMgrDetailVO.getArcReceiptDetailVO();
								if (StringUtils.isNotBlank(arcMgrDetailVO.getFileName())
										&& arcMgrDetailVO.getFileName().equals(arcSwitchDetailDTO.getFileName())) {
									if (arcReceiptDetailVO != null
											&& StringUtils.isNotBlank(arcSwitchDetailDTO.getPlaceEndNm())) {
										arcReceiptDetailVO.setArcPlaceNm(arcSwitchDetailDTO.getPlaceEndNm());
										break;
									}
								}
							}
						}
						
						
					}
				}
				return new ListPageVO<ArcBorrowDetailVO>(arcBorrowDetailVOList, arcBorrowDetailVOList.size());
			}
		}
		return null;
	}
	
	
	/**
	 * 流程附件页面：根据流程业务id，查询邮寄信息
	 */
	@RequestMapping("/arcPostInfoList.do")
	@ResponseBody
	public Object arcPostInfoList(ArcPostInfoQC qc) {

		if(qc.getArcAppId() != null) {
			qc.setArcAppType(ArchiveConstants.ARC_POST_INFO_BORROW);//借阅类型
			qc.setIsDel(ArchiveConstants.IS_DEL);
			
			List<ArcPostInfoVO> voList = this.arcPostInfoService.searchList(qc);
			if(voList != null && voList.size() >0) {
				return new ListPageVO<ArcPostInfoVO>(voList, voList.size());
			}
		}
		return null;
	}
	
	
	/**
	 * 邮寄新增和修改
	 */
	@RequestMapping(value = "/arcPostInfoSave.do")
	@ResponseBody
	public Object arcPostInfoSave(ArcPostInfoVO entity,HttpServletRequest request){
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
		try {
			
			//接收方式为直递，不保存邮寄方式
			if("1".equals(entity.getSendType())) {
				entity.setSendCompany("");
				entity.setSendNum("");
				entity.setSendAddr("");
			}
			
			if(entity.getId() == null) {//新增
				
				entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
				entity.setCrtTm(new Date());
				entity.setArcAppType(ArchiveConstants.ARC_POST_INFO_BORROW);//借阅类型
				
				Long id = this.arcPostInfoService.add(entity);
				result.setData(id);
			}else {//修改
				
				ArcPostInfoVO vo = this.arcPostInfoService.selectById(entity.getId());
				if(vo != null) {
//					vo.setArcAppBussType(entity.getArcAppBussType());
					vo.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
					vo.setMdfTm(new Date());
					vo.setIdCard(entity.getIdCard());
					vo.setRecipient(entity.getRecipient());
					vo.setMobile(entity.getMobile());
					vo.setSendType(entity.getSendType());
					vo.setSendCompany(entity.getSendCompany());
					vo.setSendNum(entity.getSendNum());
					vo.setSendAddr(entity.getSendAddr());
					
					if(this.arcPostInfoService.modify(vo)) {
						result.setInfo(SysLogConstant.LOG_CMM_UPDATE_SUCC);
					}
				}
			}
			BaseLogUtils.info(logger, "save", "操作数据. DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "save", "操作数据失败.DATA:" + JSONObject.toJSONString(entity) + ex.getMessage(), CurrentThreadContext.getCurrentUserName(),ex);
		}
		return result;
	}
	
	/**
	 * 跳转到流程列表页面
	 */
	@RequestMapping("/flowList.do")
	public String flowList(HttpServletRequest request) {

		request.setAttribute("contractNo", request.getParameter("contractNo"));
		request.setAttribute("paySchNo", request.getParameter("paySchNo"));
		
		return "archive/arcBorrowMain/arcBorrowMainFlowList";
	}
	
	/**
	 * 流程列表数据
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/borrowFlowPage.do")
	@ResponseBody
	public Object borrowFlowPage(ArcBorrowMainQueryCondition qc,HttpServletRequest request) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

		qc.setIsDel(ArchiveConstants.IS_DEL);
	
		page.setCondition(qc);

		page = this.arcBorrowMainService.borrowFlowPage(page);
		List<Map<String, Object>> list = (List<Map<String, Object>>) page.getResultList();
		BaseLogUtils.info(logger, "borrowFlowPage", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return new ListPageVO<Map<String, Object>>(list, page.getTotalCount());
	}
	
	
	/**
	 * 汇总详情
	 */
	@RequestMapping(value = "/viewTotal.do")
	public Object viewTotal(ArcBorrowMainVO arcBorrowMainVO,HttpServletRequest request) {

		//1、查询档案管理主表，获取 合同号、交接单名称、档案袋号
		ArcMgrMainQC qc = new ArcMgrMainQC();
		qc.setContractNo(arcBorrowMainVO.getContractNo());
		List<ArcMgrMainVO> arcMgrMainVOList = arcMgrMainService.selectList(qc);
		if(arcMgrMainVOList != null && arcMgrMainVOList.size() >0) {
			ArcMgrMainVO arcMgrMainVO = arcMgrMainVOList.get(0);
			//查询承租人
			arcMgrMainVO.setCstNm(arcBorrowMainService.getCstNm(arcBorrowMainVO.getContractNo()));
			request.setAttribute("arcMgrMainVO", arcMgrMainVO);
		}
		
		//2、前台传来的多个支付表号
		if(StringUtils.isNotBlank(arcBorrowMainVO.getPaySchNoList())) {
			request.setAttribute("paySchNoArray",arcBorrowMainVO.getPaySchNoList().split(";"));
		}
		
		return "archive/arcBorrowMain/arcBorrowMainViewTotal";
	}
	
	/**
	 * 借阅历史
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/borrowHistoryPage.do")
	@ResponseBody
	public Object borrowHistoryPage(ArcBorrowMainQueryCondition qc,HttpServletRequest request) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}
		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}

	
		page.setCondition(qc);

		page = this.arcBorrowMainService.borrowHistoryPage(page);
		List<Map<String, Object>> list = (List<Map<String, Object>>) page.getResultList();
		BaseLogUtils.info(logger, "borrowHistoryPage", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return new ListPageVO<Map<String, Object>>(list, page.getTotalCount());
	}
	
	/**
	 */
	@RequestMapping("/borrowRecord.do")
	@ResponseBody
	public Object borrowRecord(ArcBorrowDetailQueryCondition condition) {

		if(condition.getArcMgrDetailId() != null) {
			
			
			List<Map<String, Object>> list = this.arcBorrowMainService.borrowRecord(condition);
			if(list != null && list.size() >0) {
				for (Map<String, Object> map : list) {
					//判断是否能发起延期申请 1、计划归还  2、当前节点是借阅人归还
					map.put("canDelayApply", this.arcBorrowMainService.canDelayApply((String)map.get("ORIGINAL_RETURN"),(String)map.get("P_NO")));
				}
				return new ListPageVO<Map<String, Object>>(list, list.size());
			}
		}
		return null;
	}
	
	
	
	/**
	 * 延期申请页面
	 */
	@RequestMapping(value = "/delayApply.do")
	public Object delayApply(Long id,HttpServletRequest request) {

		request.setAttribute("id", id);
		//1、查询借阅主表，获取 合同号、交接单名称、档案袋号
		if(id != null) {
			ArcBorrowMainVO arcBorrowMainVO = this.arcBorrowMainService.selectById(id);
			if(arcBorrowMainVO != null) {
				//2、查询当前借阅下对应的支付表号
				List<String> paySchNoList = new ArrayList<String>();
				ArcBorrowDetailQueryCondition qc = new ArcBorrowDetailQueryCondition();
				qc.setArcBorrowMainId(arcBorrowMainVO.getId());
				qc.setArcLevel(ArchiveConstants.ARCLEVEL_2);
				List<ArcBorrowDetailVO> arcBorrowDetailVOList = this.arcBorrowDetailService.searchList(qc);
				if(arcBorrowDetailVOList != null && arcBorrowDetailVOList.size() >0) {
					for (ArcBorrowDetailVO arcBorrowDetailVO : arcBorrowDetailVOList) {
						if(StringUtils.isNotBlank(arcBorrowDetailVO.getPaylistCode()) && !paySchNoList.contains(arcBorrowDetailVO.getPaylistCode())) {
							paySchNoList.add(arcBorrowDetailVO.getPaylistCode());
						}
					}
				}
				
				//查询承租人
				if(StringUtils.isNotBlank(arcBorrowMainVO.getContractNo())) {
					arcBorrowMainVO.setCstNm(arcBorrowMainService.getCstNm(arcBorrowMainVO.getContractNo()));
				}
				
				request.setAttribute("paySchNoList", paySchNoList);
				request.setAttribute("paySchNoListStr", org.apache.commons.lang3.StringUtils.join(paySchNoList, ","));
				request.setAttribute("arcBorrowMainVO", arcBorrowMainVO);
			}
		}
		
		//2、判断当前哪个节点
		String from = request.getParameter("from");
		if("delayApply".equals(from)) {//如果是申请页面，则清空延期原因
			ArcBorrowMainVO arcBorrowMainVO = (ArcBorrowMainVO)request.getAttribute("arcBorrowMainVO");
			if(arcBorrowMainVO != null) {
				arcBorrowMainVO.setDelayReason("");
			}
		}
		request.setAttribute("from", from);
		
		
		return "archive/arcBorrowMain/arcBorrowMainDelayApply";
	}

	/**
	 * 延期申请保存
	 */
	@RequestMapping(value = "/delayApplySave.do")
	@ResponseBody
	public Object delayApplySave(ArcBorrowMainVO arcBorrowMainVO,HttpServletRequest request) {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,
				SysLogConstant.LOG_CMM_OPERATE_SUCC);

		try {

			//1、验证
			//1.1 借阅主表必须存在
			ArcBorrowMainVO arcBorrowMain = this.arcBorrowMainService.selectById(arcBorrowMainVO.getId());
			if(arcBorrowMain == null) {
				BaseLogUtils.error(logger, "delayApplySave", "没有查询到借阅主表数据,id:"+arcBorrowMainVO.getId(),CurrentThreadContext.getCurrentUserName());
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("没有查询到借阅主表数据,id:"+arcBorrowMainVO.getId());
				return result;
			}
			//1.2 如果需要发起延期流程，需要检测是否已经发起，如果存在流程中的延期申请，则不能再发起
			String from = request.getParameter("from");
			if("delayApply".equals(from)) {
				boolean pass = this.arcBorrowMainService.getFlowIsCanBeStart(arcBorrowMainVO.getId()
						, CurrentThreadContext.getCurrentSysCd(), ArchiveConstants.ARC_FLOW_S_H_ARC, ArchiveConstants.FLOW_KEY_BORROW_DELAY, null,true);
				if(!pass){
					BaseLogUtils.error(logger, "delayApplySave", "已有流程审核中,不能再发起,id:"+arcBorrowMainVO.getId(),CurrentThreadContext.getCurrentUserName());
					result.setSuccess(BaseConstant.IS_YESNO_NO);
					result.setInfo("已有流程审核中,不能再发起,id:"+arcBorrowMainVO.getId());
					return result;
				}
			}
			
			//2、数据保存
			List<ArcBorrowDetailVO> arcBorrowDetailList = (List<ArcBorrowDetailVO>) JsonUtil.toList(
					request.getParameter("_arcBorrowDetailList"),new ArcBorrowDetailVO());
			if (arcBorrowDetailList != null && arcBorrowDetailList.size() > 0) {
				for (ArcBorrowDetailVO entity : arcBorrowDetailList) {
					if (entity.getId() != null) {// 修改
						ArcBorrowDetailVO vo = this.arcBorrowDetailService.selectById(entity.getId());
						if (vo != null && "1".equals(vo.getOriginalReturn())) {//只更新需归还的资料
							vo.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
							vo.setMdfTm(new Date());
							vo.setDelayDate(entity.getDelayDate());//延期时间
							this.arcBorrowDetailService.modify(vo);//借阅明细更新
						}
					}
				}
			}
			
			
			if("delayApply".equals(from) || "delayUpdate".equals(from) ) {//新增和修改
				//保存延期申请原因
				arcBorrowMain.setDelayReason(arcBorrowMainVO.getDelayReason());
				arcBorrowMain.setMdfTm(new Date());
				arcBorrowMain.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
				this.arcBorrowMainService.update(arcBorrowMain);//借阅主表更新
			}
			
			//3、发起延期流程
			if("delayApply".equals(from) && arcBorrowMainVO.getId() != null) {
				result = delayApplyFlowStart(arcBorrowMain);//发起延期申请流程
			}
			
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "delayApplySave", "操作数据失败.DATA:"+ ex.getMessage(),
					CurrentThreadContext.getCurrentUserName(), ex);
		}
		return result;
	}
	
	
	/**
	 *  延期申请流程发起
	 */
	private DataResultVO delayApplyFlowStart(ArcBorrowMainVO arcBorrowMain) {
		
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(arcBorrowMain.getId())){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "delayApplyFlowStart", SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY, CurrentThreadContext.getCurrentUserName());
			return result;
		}
		
		FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
		try {
			//流程定义Key和流程定义ID 如果是前端选择的则直接指定,如果不是则系统自动按照配置选择唯一一条记录,如果找不到会提示
			flowStartParamsDTO.setBusinessKey(String.valueOf(arcBorrowMain.getId())); 
			flowStartParamsDTO.setIsFlowStatePassCanbeStart(true);//存在审核通过的流程，可以再次发起
			flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
			flowStartParamsDTO.setWordsInTheTable(ArchiveConstants.ARC_FLOW_S_H_ARC);
			flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			flowStartParamsDTO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
			flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
			flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
			flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);//优先级,可以在界面定义
			
			//设置关键字 开始
			StringBuffer keyWords = new StringBuffer();
			
			String cstMgrOrgCd = arcBorrowMainService.getCstMgrOrgCd(arcBorrowMain.getContractNo());//根据合同号获取客户经理组织架构
			if(StringUtils.isNotBlank(cstMgrOrgCd)) {
				if(cstMgrOrgCd.length() > 12) {//只截取事业部-省公司
					cstMgrOrgCd = cstMgrOrgCd.substring(0,12);
				}
				SysOrgDTO sysOrgDTO = this.sysOrgApiService.selectSysOrgByOrgCd(cstMgrOrgCd, CurrentThreadContext.getCurrentSysCd());
				if(sysOrgDTO != null) {
					keyWords.append(sysOrgDTO.getOrgDispNm()).append(FlowConstant.FLOW_TASK_BACK_USR_DISPLAY_SEPERATOR);//组织架构（架构显示名称,例如:重卡-江苏-南京分公司）
				}
			}
			keyWords.append(arcBorrowMain.getContractNo()).append(FlowConstant.FLOW_TASK_BACK_USR_DISPLAY_SEPERATOR);//合同号
			
			flowStartParamsDTO.setSearchDesc(keyWords.toString()); 
			BaseLogUtils.info(logger, "delayApplyFlowStart", "keyWords：" +keyWords.toString(), CurrentThreadContext.getCurrentUserName());
			//设置关键字 结束
			
			
			flowStartParamsDTO.setModelTyp(ArchiveConstants.FLOW_MODEL_TYP_ARC_BORROW_DELAY);//延期流程
			flowStartParamsDTO.setCstNm(arcBorrowMainService.getCstNm(arcBorrowMain.getContractNo()));
            
			DataResultDTO dataResultDTO = this.arcBorrowMainService.addFlowStart(flowStartParamsDTO);
			if(!dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
			}
			if(null!=dataResultDTO && null!=dataResultDTO.getData()){
				FlowStartedDTO flowStartedDTO = (FlowStartedDTO) dataResultDTO.getData();
				if(StringUtils.isNotBlank(flowStartedDTO.getNextOperUsrNames())){
	                result.setInfo("下一个节点操作人:"+flowStartedDTO.getNextOperUsrNames());
	            }else{
	                result.setInfo("流程发起成功");
	            }
			}
			
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "delayApplyFlowStart", "错误[BaseException],请求参数：" + JSONObject.toJSONString(flowStartParamsDTO) + " -ERROR:" +e.getMessage(), CurrentThreadContext.getCurrentUserName());
			e.getStackTrace();
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "delayApplyFlowStart", "错误[Exception],请求参数：" + JSONObject.toJSONString(flowStartParamsDTO) + " -ERROR:" +e.getMessage(), CurrentThreadContext.getCurrentUserName());
			e.getStackTrace();
		}
		return result;
	}
	
	/**
	 * 保存上传记录
	 */
	@RequestMapping(value = "/saveUploadRecord.do")
	@ResponseBody
	public Object saveUploadRecord(HttpServletRequest request) throws Exception {
		String attchmnt = request.getParameter("attchmnt");
		String businessKey = request.getParameter("businessKey");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_FILE_UPLOAD_SUCC);
		if(StringUtils.isNotEmpty(attchmnt) && StringUtils.isNotEmpty(businessKey)){
			//上传解析
			try{
				String fileRem = ""; //文件说明
				String cfgDtlCd = ""; //配置子编号
				String tabNm = ""; //数据表名
				String cfgCd = ArchiveConstants.ARC001; //配置编号：REF001
				String cfgOrgCd = ArchiveConstants.ORG_CODE; //组织架构代码：0000
				//判断标识确定文件配置编码
				fileRem = "";
				tabNm = ArchiveConstants.ARC_BORROW_MAIN_TABNM; //借阅主表
				cfgDtlCd = ArchiveConstants.ARC_BORROW_MAIN_CFGDTLCD_10;
				
				
				Boolean attchmntPass = this.sysUlFilesRecService.addAttchmnt(businessKey, attchmnt, cfgCd, cfgDtlCd, tabNm, fileRem, null, null, false, cfgOrgCd);
				if(null == attchmntPass || attchmntPass == false){
					result.setSuccess(BaseConstant.IS_YESNO_NO);
					result.setInfo("附件上传失败!");
					BaseLogUtils.info(logger, "uploadAttchment", "附件上传失败1.[id="+businessKey+"]", CurrentThreadContext.getCurrentUserName());
				}
				result.setData(businessKey);//设置附件关联主键
			}catch (Exception ex) {
				ex.printStackTrace();
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
				BaseLogUtils.error(logger, "uploadAttchment", "附件上传失败3.[businessKey="+businessKey+"]", CurrentThreadContext.getCurrentUserName(), ex);
			}
		}
		return result;
	}
	
	/**
	 * 判断客户是否逾期
	 *  验证：如果当前角色为客户经理、分公司经理、城市经理（数据字典配置 ARC023）,则需要判断客户是否逾期 ，如果逾期不允许发起借阅流程
	 */
	@RequestMapping(value = "/checkCstOverdue.do")
	@ResponseBody
	public Object checkCstOverdue(HttpServletRequest request){
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		try {
			
			String contractNo = request.getParameter("contractNo");
			if(StringUtils.isBlank(contractNo)) {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("合同号contractNo不能为空");
				return result;
			}
			
			Long currentRoleId = CurrentThreadContext.getCurrentRoleId();//当前角色ID
			List<KeyValueVO> keyValueVOList = arcBscInfoService.getKvList(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd()
					, ArchiveConstants.DIC_BORROW_ROLE);//配置的角色列表
			BaseLogUtils.info(logger, null, "是否需要判断客户是否逾期开始 currentRoleId:"+currentRoleId +" keyValueVOList:"+ JSONObject.toJSONString(keyValueVOList), CurrentThreadContext.getCurrentUserName());
			if(currentRoleId != null && CollectionUtils.isNotEmpty(keyValueVOList)) {
				for (KeyValueVO keyValueVO : keyValueVOList) {
					if(currentRoleId.toString().equals(keyValueVO.getKey())) {
						//需要验证当前角色，查询客户是否有逾期，如果有逾期，则不能发起借阅
						if(StringUtils.isNotBlank(contractNo)) {
							
							PrjBscInfoQueryCondition qc = new PrjBscInfoQueryCondition();
							qc.setLsCntNo(contractNo);
							BaseLogUtils.info(logger, null, "根据合同号查询客户id开始,qc:"+ JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
							List<PrjBscInfoVO> prjBscInfoVOList = prjBscInfoService.searchPrjBscInfoList(qc);
							BaseLogUtils.info(logger, null, "根据合同号查询客户id结束,prjBscInfoVOList:"+ JSONObject.toJSONString(prjBscInfoVOList), CurrentThreadContext.getCurrentUserName());
							
							if(CollectionUtils.isNotEmpty(prjBscInfoVOList)){
								
								Long cstId = prjBscInfoVOList.get(0).getCstId();
								BaseLogUtils.info(logger, null, "根据客户id查询是否逾期开始,cstId:"+ cstId, CurrentThreadContext.getCurrentUserName());
								Long relCstId = this.arcBorrowMainService.selectCstIsOvd(cstId);
								BaseLogUtils.info(logger, null, "根据客户id查询是否逾期结束,relCstId:"+ relCstId, CurrentThreadContext.getCurrentUserName());
								
								if(relCstId != null) {
									result.setSuccess(BaseConstant.IS_YESNO_NO);
									result.setInfo("该客户存在逾期，不可发起借阅");
									return result;
								}
							}
						}
						
						break;
					}
				}
			}
				
				
		}catch (Exception ex) {
			ex.printStackTrace();
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.error(logger, "", "checkCstOverdue失败.异常信息:" +  ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
}

